﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace SuperX.Common.Helper
{

    /// <summary>
    /// api数据结构
    /// </summary>
    [DataContract(Namespace = "WebAPI")]
    [Serializable]
    public class InvokeMsg
    {
        [DataMember]
        public MethodType MethodType { get; set; } = MethodType.IO;

        /// <summary>
        /// 方法名称
        /// </summary>
        [DataMember]
        public string MethodName { get; set; } = "";

        /// <summary>
        /// 参数
        /// </summary>
        public string ParaString
        {
            get
            {
                return this._paraString;
            }
            set
            {
                if (value != this._paraString)
                {
                    this._paraString = value;
                    this.Paras = JsonHelper.JsonDeserialize<object[]>(this._paraString);
                }
            }
        }

        /// <summary>
        /// 参数对象
        /// </summary>
        [DataMember]
        public object[] Paras { get; set; } = new object[0];

        /// <summary>
        /// 操作是否成功，默认为True
        /// </summary>
        [DataMember]
        [JsonProperty(DefaultValueHandling = 0)]
        public bool IsSuccess { get; set; } = true;

        /// <summary>
        /// 错误信息
        /// </summary>
        [DataMember]
        public string ErrorMsg { get; set; } = "";

        /// <summary>
        /// 返回的序列化对象
        /// </summary>
        [DataMember]
        public string ReturnBody { get; set; } = "";

        /// <summary>
        /// 请求ID
        /// </summary>
        [DataMember]
        public string RequestID { get; set; } = "";

        // 
        public InvokeMsg()
        {
        }

        // 
        public InvokeMsg(MethodType methodType, string methodName) : this()
        {
            this.MethodType = methodType;
            this.MethodName = methodName;
        }

        private string _paraString;
    }
}
